<template>
    <div class="goods">
        <div class="goodsTop">
            <van-button @click="n=index" v-for="(item,index) in navs" :key="item" :class="n==index?'active':''">{{ item }}</van-button>
        </div>
         <div v-if="goods.length > 0">
            <van-card
                v-for="item in goods[n].content"
                :key="item.id"
                :title="item.goodsname"
                :thumb="$pre + item.img"
                @click="$router.push('/detail/' + item.id)"
            >
                <div slot="price" class="text-primary h3">￥{{ item.price | filterPrice }}</div>
            </van-card>
        </div>
    </div>
</template>

<script>
import {reqHomeGoods} from "../../../http/api"
export default {
    data() {
        return {
            //初始化
            navs: ["热门推荐", "上新推荐", "所有商品"],
            goods: [],
            n: 0,
        }
    },
    mounted() {
        reqHomeGoods().then((res)=>{
            if(res.data.code == 200){
                this.goods = res.data.list
            }
        })
    }
}
</script>

<style scoped lang="less">
@import url(../../../less/index.less);
.goodsTop{
    display: flex;
}
.goodsTop button{
    flex: 1;
}
.goodsTop .active{
    background-color: #ff4400;
    color: #fff;
}
.goods div:nth-child(2){
    margin-top: 0.1rem;
}
.van-card__title{
    font-size: 0.3rem;
    font-weight: 500;
    color: rgb(39, 37, 37);
}
</style>